package com.zyplayer.doc.data.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.zyplayer.doc.data.config.security.DocUserDetails;
import com.zyplayer.doc.data.config.security.DocUserUtil;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 插入数据库自动填充配置
 * @author : caiyi
 * @description :
 * @createDate : 2024/11/29 9:54
 */
@Component
public class BatisMetaObjectHandle  implements MetaObjectHandler
{
    @Override
    public void insertFill(MetaObject metaObject)
    {
        try {
            DocUserDetails currentUser = DocUserUtil.getCurrentUser();

            this.strictInsertFill(metaObject, "tenantId", Long.class, currentUser.getTenantId());
            this.strictInsertFill(metaObject, "createUserId", Long.class, currentUser.getUserId());
            this.strictInsertFill(metaObject, "createUserName", String.class, currentUser.getUsername());
            this.strictInsertFill(metaObject, "createTime", Date.class, new Date());

        } catch (Exception e) {

        }
    }

    @Override
    public void updateFill(MetaObject metaObject)
    {

    }
}
